﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Learnive.Models;

namespace Learnive.Controllers
{
    public class CijferController : Controller
    {
        private LearniveContext db = new LearniveContext();

        //
        // GET: /Cijfer/

        public ActionResult Index()
        {
            var cijfers = db.Cijfers.Include(c => c.Vak);
            return View(cijfers.ToList());
        }

        //
        // GET: /Cijfer/Details/5

        public ActionResult Details(int id = 0)
        {
            Cijfer cijfer = db.Cijfers.Find(id);
            if (cijfer == null)
            {
                return HttpNotFound();
            }
            return View(cijfer);
        }

        //
        // GET: /Cijfer/Create

        public ActionResult Create()
        {
            ViewBag.vakID = new SelectList(db.Vakjes, "vakID", "vakCode");
            return View();
        }

        //
        // POST: /Cijfer/Create

        [HttpPost]
        public ActionResult Create(Cijfer cijfer)
        {
            if (ModelState.IsValid)
            {
                db.Cijfers.Add(cijfer);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.vakID = new SelectList(db.Vakjes, "vakID", "vakCode", cijfer.vakID);
            return View(cijfer);
        }

        //
        // GET: /Cijfer/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Cijfer cijfer = db.Cijfers.Find(id);
            if (cijfer == null)
            {
                return HttpNotFound();
            }
            ViewBag.vakID = new SelectList(db.Vakjes, "vakID", "vakCode", cijfer.vakID);
            return View(cijfer);
        }

        //
        // POST: /Cijfer/Edit/5

        [HttpPost]
        public ActionResult Edit(Cijfer cijfer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(cijfer).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.vakID = new SelectList(db.Vakjes, "vakID", "vakCode", cijfer.vakID);
            return View(cijfer);
        }

        //
        // GET: /Cijfer/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Cijfer cijfer = db.Cijfers.Find(id);
            if (cijfer == null)
            {
                return HttpNotFound();
            }
            return View(cijfer);
        }

        //
        // POST: /Cijfer/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Cijfer cijfer = db.Cijfers.Find(id);
            db.Cijfers.Remove(cijfer);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}